const mysql = require('mysql');
const connection = mysql.createConnection({
  host : '127.0.0.1',
  // port : 3306
  user :'root',
  password : 'root',
  database : 'baixiu'
});

module.exports = {
  // 封装一个验证用户名和密码是否一致的方法
  validateEmailAndPassword(email,password,callback){
    let sql = `SELECT * FROM users WHERE email='${email}' AND \`password\`='${password}'`;
    connection.query(sql,(err,result)=>{
      callback(err,result[0]);
    })
  },
  // 封装一个获取所有用户的方法
  getAllUser(callback){
    let sql = 'SELECT * FROM users WHERE isDelete=0';
    connection.query(sql,(err,result)=>{
      callback(err,result);
    })
  },
  deleteUserById(id,callback){
    let sql = `UPDATE users SET isDelete=1 WHERE id=${id}`;
    connection.query(sql,(err,result)=>{
      callback(err,result);
    })
  }
}